#include<iostream>
#include<vector>
#include<fstream>
#include<sstream>
#include"prototype.h"
#include"products.h"
#include<windows.h>
#include"winsock.h"
#include"mysql.h"
#include"DB_worker.h"

#include <QApplication>
#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QWidget>
#include <QTimer>
#include <QWidget>
#include <QImage>
#include <QTextBrowser>
#include"ui_finder.h"
#include "lookers.h"

void test0()
{
	std::ifstream infos("D:\\Originalcodes\\Field_of_C++\\bjut_cpp_2\\infos.txt");
	std::string info_("");
	std::vector<common_employee> employees(0);

	while (getline(infos, info_)) {
		std::istringstream info(info_);
		std::string temp_id, temp_name, kind;
		int hours(0), soild_salary(0), sale_amount(0);

		info>>temp_id>>temp_name>>kind>>hours>>soild_salary>>sale_amount;
		common_employee temp_employee(temp_id, temp_name, kind, hours, soild_salary, sale_amount);
		auto f = [kind, hours, soild_salary, sale_amount] {
			if (kind == "technician") std::cout<<"hours:"<<hours<<std::endl;
			if (kind == "manager")  std::cout<<"soild_salary:"<<soild_salary<<std::endl;
			if (kind == "salesman") std::cout<<"sale_amount:"<<sale_amount<<std::endl;
			if (kind == "salesmanager") std::cout<<"solid_salary:"<<soild_salary<<std::endl
											     <<"sale_amount:"<<sale_amount<<std::endl;
		};

		std::cout<<std::endl
		         <<"id:"<<temp_employee.get_id()<<std::endl
		         <<"name:"<<temp_employee.get_name()<<std::endl
		         <<"kind:"<<temp_employee.get_kind()<<std::endl;
		         f();
		std::cout<<"salary:"<<temp_employee.get_salary()<<std::endl
				 <<std::endl;
	}
}
void test00()
{
	DB_worker sqlBoy;
	std::ifstream infos("D:\\Originalcodes\\Field_of_C++\\bjut_cpp_2\\infos.txt");
	std::string info_("");
	common_employee employees[4];
	int i = 0;

	while (getline(infos, info_)) {
		std::istringstream info(info_);
		std::string temp_id, temp_name, kind;
		int hours(0), soild_salary(0), sale_amount(0);

		info>>temp_id>>temp_name>>kind>>hours>>soild_salary>>sale_amount;
		common_employee temp_employee(temp_id, temp_name, kind, hours, soild_salary, sale_amount);
		employees[i++] = temp_employee;
	}

	for (auto& x: employees) {
		sqlBoy.insert(x);
		sqlBoy.stringlize(sqlBoy.get(x.get_id()));
	}
}
void test1(int args, char* argv[])
{
	QApplication a(args, argv);
	looker now("D:\\Originalcodes\\Field_of_C++\\bjut_cpp_2\\infos.txt");
	now.in_terminal();
	a.exec();
}
void test2(int args, char* argv[])
{
	QApplication a(args, argv);
	looker now("D:\\Originalcodes\\Field_of_C++\\bjut_cpp_2\\infos.txt");
	now.in_GUI();
	a.exec();
}
int main(int args, char* argv[])
{
	//test0();//基本功能
	//test00();//mysql测试
	//test1(args, argv);//测试用例一
	test2(args, argv);//测试用例二
}
